package com.hjm.project.bounty.bounty.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.project.system.dict.domain.DictData;
import com.hjm.project.system.dict.mapper.DictDataMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hjm.project.bounty.bounty.mapper.SpecialBountyMapper;
import com.hjm.project.bounty.bounty.domain.SpecialBounty;
import com.hjm.project.bounty.bounty.service.ISpecialBountyService;
import com.hjm.common.utils.text.Convert;

/**
 * 盟主引流特别奖励Service业务层处理
 * 
 * @author LOVE
 * @date 2020-11-24
 */
@Service
public class SpecialBountyServiceImpl implements ISpecialBountyService 
{
    @Autowired
    private SpecialBountyMapper specialBountyMapper;
    @Autowired
    private DictDataMapper dictDataMapper;

    /**
     * 查询盟主引流特别奖励
     * 
     * @param id 盟主引流特别奖励ID
     * @return 盟主引流特别奖励
     */
    @Override
    public SpecialBounty selectSpecialBountyById(Long id)
    {
        return specialBountyMapper.selectSpecialBountyById(id);
    }

    /**
     * 查询盟主引流特别奖励列表
     * 
     * @param specialBounty 盟主引流特别奖励
     * @return 盟主引流特别奖励
     */
    @Override
    public List<SpecialBounty> selectSpecialBountyList(SpecialBounty specialBounty)
    {
        return specialBountyMapper.selectSpecialBountyList(specialBounty);
    }

    /**
     * 新增盟主引流特别奖励
     * 
     * @param params 盟主引流特别奖励
     * @return 结果
     */
    @Override
    public AjaxResult insertSpecialBounty(Map<String,String> params)
    {
        List<DictData> dictDatas = (List<DictData>)dictDataMapper.selectDictDataByType("special_bounty_gear");
        List<SpecialBounty> list=new ArrayList<>();
        for (DictData dictData : dictDatas) {
            SpecialBounty specialBounty=new SpecialBounty();
            if (StringUtils.isNotBlank(params.get("id"+dictData.getDictValue()))){
                specialBounty.setId(Long.parseLong(params.get("id"+dictData.getDictValue())));
            }
            specialBounty.setNumbers(Long.parseLong(params.get("numbers"+dictData.getDictValue())));
            specialBounty.setSumMoney(params.get("sumMoney"+dictData.getDictValue()));
            specialBounty.setBountyMonthShow(params.get("bountyMonthShow"+dictData.getDictValue()));
            specialBounty.setBountyMonthHide(params.get("bountyMonthHide"+dictData.getDictValue()));
            if (StringUtils.isNotBlank(params.get("gear"+dictData.getDictValue()))){
                specialBounty.setGear(Long.parseLong(params.get("gear"+dictData.getDictValue())));
            }else{
                specialBounty.setGear(Long.parseLong(dictData.getDictValue()));
            }
            list.add(specialBounty);

        }
        if (list.size()>0){
            for (SpecialBounty specialBounty : list) {
                if (null!=specialBounty.getId()){
                    specialBountyMapper.updateSpecialBounty(specialBounty);
                }else{
                    specialBountyMapper.insertSpecialBounty(specialBounty);
                }
            }
            return AjaxResult.success();
        }else{
            return AjaxResult.error("请填写数据");
        }
    }

    /**
     * 修改盟主引流特别奖励
     * 
     * @param specialBounty 盟主引流特别奖励
     * @return 结果
     */
    @Override
    public int updateSpecialBounty(SpecialBounty specialBounty)
    {
        return specialBountyMapper.updateSpecialBounty(specialBounty);
    }

    /**
     * 删除盟主引流特别奖励对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSpecialBountyByIds(String ids)
    {
        return specialBountyMapper.deleteSpecialBountyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除盟主引流特别奖励信息
     * 
     * @param id 盟主引流特别奖励ID
     * @return 结果
     */
    @Override
    public int deleteSpecialBountyById(Long id)
    {
        return specialBountyMapper.deleteSpecialBountyById(id);
    }
}
